package com.yunhe.sms.view.user;

import com.yunhe.sms.control.TeacherController;
import com.yunhe.sms.dao.TeacherDao;
import com.yunhe.sms.mode.Teacher;
import com.yunhe.sms.mode.User;

import java.awt.*;
import java.util.Scanner;

/**
 * 添加/修改用户页面
 */
public class UserAdd {
    public static User userAddUI() throws Exception{
        System.out.println("********************学员信息管理系统-用户管理-添加/修改********************");
        Scanner sc = new Scanner(System.in);
        System.out.print("要添加/修改的用户编号：");
        String id = sc.next();
        System.out.print("用户名：");
        String userName = sc.next();
        System.out.print("用户密码：");
        String password = sc.next();
        System.out.print("真实姓名：");
        String realName = sc.next();
        System.out.print("用户类型（讲师/管理员）：");
        String type = sc.next();
        Teacher teacher = null;
        if (type!=null&&type.equals(User.TYPE_TEACHER_STR)){
            System.out.print("请输入讲师工号");
            Integer teacherId = sc.nextInt();
            teacher = TeacherDao.getOneTeacher(teacherId);
            if (teacher==null){
                throw new Exception("请先添加讲师后创建讲师用户！");
            }
        }
        return new User(id,userName,password,realName,type,teacher);
    }
}
